﻿/**	\file		lxpref_main.cpp
 *	\date		(2014-11-17 23:48:42)/(2015-01-01 00:38:39)
 *-----------------------------------------------------------------------------
 *	\brief
 *	\version	1.0.0.2
 *	\author		Nick Shallery	(nicknide@gmail.com)
 *	\copyright	YOU HAVE ALL LEFT WITH THIS CODE WHILE YOU KEEP COMMENT IN EVERY COPY.
 *-----------------------------------------------------------------------------
**/

//#include	<lolix/imp/lolix_plugin_auto_release_lib.h>

#include	"./lxprofile.hxx"
#include	"./lxpref_fac.hxx"

#include	"../lxsamsara/recurrence.h"

#include	<lxnet/lxnet_itf.h>
#include	<lolix/toy/stdc_fun.h>
#include	<lxut/ctrl/ctrl_string.h>

#include	<lolix/imp/lolix_plugin_enter.inl>
#include	<lolix/imp/lolix_plugin_auto_release_lib.inl>

void
__Init_cnt_table(void);

extern "C" lolix::LOLIX_RETNV	LOLIX_CALL lxpLoading(lolix::lolix_inst* lx_inst, lolix::lolix_regist* lx_reg)
{
	lolix::LOLIX_RETNV rtv;
	lolix::dynamic_allocator* alc;
	if ( LOLIX_CHECK_ERROR(rtv = lx_reg->query_itf(&alc)) )
		return rtv;
	atexit_release(*alc);
	lolix::ref_factory* ref_fac;
	if ( LOLIX_CHECK_ERROR(rtv = lx_reg->query_itf(&ref_fac)) )
		return rtv;
	atexit_release(*ref_fac);

	lolix::loli::cs_factory* cs_fac;
	if ( LOLIX_CHECK_ERROR(rtv = lx_reg->query_itf(&cs_fac)) )
		return rtv;
	atexit_release(*cs_fac);

	lolix::loli::thread_factory* td_fac;
	if ( LOLIX_CHECK_ERROR(rtv = lx_reg->query_itf(&td_fac)) )
		return rtv;
	atexit_release(*td_fac);

	lolix::toy::time_info* tinf;
	if ( LOLIX_CHECK_ERROR(rtv = lx_reg->query_itf(&tinf)) )
		return rtv;
	atexit_release(*tinf);

	lolix::loli::signal::factory_type* sign_fac;
	if ( LOLIX_CHECK_ERROR(rtv = lx_reg->query_itf(&sign_fac)) )
		return rtv;
	atexit_release(*sign_fac);

	lxio::file_async_pool_factory* async_pool_fac;
	if ( LOLIX_CHECK_ERROR(rtv = lx_reg->query_itf(&async_pool_fac)) )
		return rtv;
	atexit_release(*async_pool_fac);

	lxnet::net_factory* net_fac;
	if ( LOLIX_CHECK_ERROR(rtv = lx_reg->query_itf(&net_fac)) )
		return rtv;
	atexit_release(*net_fac);

	lolix::toy::stdc_fun* stdc;
	if ( LOLIX_CHECK_ERROR(rtv = lx_reg->query_itf(&stdc)) )
		return rtv;
	atexit_release(*stdc);

	lxut::ctrl::ctrl_string_factory* ctrl_str_fac;
	if ( LOLIX_CHECK_ERROR(rtv = lx_reg->query_itf(&ctrl_str_fac)) )
		return rtv;
	atexit_release(*ctrl_str_fac);

	lxpref::_inst::lxprofile_inst* prf;
	if ( LOLIX_CHECK_ERROR(rtv = lxpref::_inst::lxprofile_inst::create_inst(&prf, alc, ref_fac, tinf, cs_fac, sign_fac, td_fac)) )
		return rtv;
	atexit_release(*prf);
	if ( LOLIX_CHECK_ERROR(rtv = lx_reg->reg_loli<lxpref::lxprofile>(prf)) )
		return rtv;

	lxsamsara::recurrence* recur;
	if ( LOLIX_CHECK_ERROR(rtv = lx_reg->query_itf(&recur)) )
		return rtv;
	atexit_release(*recur);

	lxpref::_inst::lxpref_fac_inst* pref_fac;
	if ( LOLIX_CHECK_ERROR(rtv = lxpref::_inst::lxpref_fac_inst::create_inst(&pref_fac, alc, async_pool_fac, ref_fac, net_fac, stdc, sign_fac, cs_fac, ctrl_str_fac, tinf, td_fac, recur)) )
		return rtv;
	atexit_release(*pref_fac);

	if ( LOLIX_CHECK_ERROR(rtv = lx_reg->reg_loli<lxpref::lxpref_fac>(pref_fac)) )
		return rtv;

	return rtv;
}


extern "C" lolix::LOLIX_RETNV	LOLIX_CALL lxpFreeing(lolix::lolix_inst* lx_inst)
{
	return lolix::imp::plugin_auto_release_lib_query(lx_inst);
}


#define	LXPREF_LIB_ID 0xf12dd41e, 0xf4734d51, 0x8ef2303a, 0x3b5cff82
LOLIX_DEF__PLUGIN_ENTER(LXPREF_LIB_ID, "lxpref", __Init_cnt_table, 0, 0, 0);
